<?php
function calStudentSemester($currentSem, $currentYear, $beginYear) {
	return ($currentYear - $beginYear) * 2 + $currentSem ;
}

function calStudentYear($classID) {
	$year = intval(substr($classID,2,2)) + 2000;
	if ($year > 2080) {
		return $year - 100;
	} else {
		return $year;
	}
}

function calGrade($finalGrade){
	if($finalGrade < 2.5) {
		return "F";
	} else if ($finalGrade < 4) {
		return "E";
	} else if ($finalGrade < 5.5) {
		return "D";
	} else if ($finalGrade < 7) {
		return "C";
	} else if ($finalGrade < 8.5) {
		return "B";
	} else {
		return "A";
	}
}

function translateApprovedCollum($text) {
	switch (strtoupper($text)) {
		case "APPROVED" :
			return "Đã chấp nhận";
			break;
		case "NOTYET" :
			return "Chưa xử lý";
			break;
	}
	return "";
}

function lookupCoursename($courseID){
	$sql = "SELECT * FROM course WHERE course_id like '".$courseID."'";
	$query = mysql_query($sql);  
	while($row=mysql_fetch_array($query)) {  
		return $row["COURSE_NAME"];
	}
}

function lookupClassName ($classID){
	$sql = "SELECT * FROM trainningclass WHERE CLASS_ID like '".$classID."'";
	$query = mysql_query($sql);  
	while($row=mysql_fetch_array($query)) {  
		return $row["CLASS_NAME"];
	}
}

function lookupTrainProgramID ($classID){
	$sql = "SELECT * FROM trainningclass WHERE CLASS_ID like '".$classID."'";
	$query = mysql_query($sql);  
	while($row=mysql_fetch_array($query)) {  
		return $row["TRNP_ID"];
	}
}

function lookupTrainProgramName ($trainPrpID){
	$sql = "SELECT * FROM trainningprogram WHERE TRNP_ID like '".$trainPrpID."'";
	$query = mysql_query($sql);  
	while($row=mysql_fetch_array($query)) {  
		return $row["TRNP_NAME"];
	}
}

function renderOpptionTag($value,$conttent,$selected) {
	if($selected) {
		echo ("<option value='".$value."' selected='".$selected."'>".$conttent."</option>");
	} else {
		echo ("<option value='".$value."'>".$conttent."</option>");
	}
}

?>